<?php

namespace App\Api\Controllers;


use Dingo\Api\Http\Request;
use EasyWeChat\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;

class WechatController extends Controller
{
    use Helpers;
    private $wechat;
    public function __construct(Application $wechat)
    {
        $this->wechat=$wechat;
    }

    /**
     * 名称：微信jssdk配置
     * 必要条件：
     * 功能：jssdk获取的ticket每天有次数限制，所以需要缓存，overtrue已经实现了。不用考虑。
     * 任务：
     */
    public function jssdk(Request $request)
    {
        if(!$request->urlString){
            return $this->response->array([
                'status_code'=>201,
                'message'=>'错误请求',
            ]);
        }
        $jssdk=$this->wechat->js;
        $jssdk->setUrl($request->urlString);//设置使用签名的路由地址
        $config=json_decode($jssdk->config([
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'scanQRCode',
        ]));
        log_arr($config);
        return $this->response->array([
            'status_code'=>200,
            'message'=>'获取数据成功',
            'result'=>$config
        ]);
    }

}
